package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entity.Product_Info;
import entity.User;
import service.OrderCartService;
import service.ProductInfoService;
import service.UserService;
import service.WarehouseProductService;
import service.impl.OrderCartServiceImpl;
import service.impl.ProductInfoServiceImpl;
import service.impl.UserServiceImpl;
import service.impl.WarehouseProductServiceImpl;


public class RemoveCarOrderServlet extends HttpServlet {
	private ProductInfoService pis = new ProductInfoServiceImpl();
	private OrderCartService ocs = new OrderCartServiceImpl();
	private UserService us = new UserServiceImpl();
	private WarehouseProductService wps = new WarehouseProductServiceImpl();
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		//获取前端的值
		String uname = request.getParameter("uname");
		String currentName = request.getParameter("currentName");
		String modle_id = request.getParameter("modle_id");
		String currentCount = request.getParameter("currentCount");
		//通过用户名查找用户
		User user = us.queryUserByName(uname);
		//通过当前的产品名称获取到产品信息
		Product_Info pi = pis.queryProduct_InfoByName(currentName);
		//通过产品id和型号id查询库存信息
		Integer wp_id = wps.queryWarehouseProductIdByProductIdAndModelId(pi.getProduct_id(), Integer.parseInt(modle_id));
		int i = ocs.deleteOrderCartByUidAndPidAndMid(pi.getProduct_id(), Integer.parseInt(modle_id), user.getUserId());
		if(i==1){
			boolean b = wps.updateWarehouse_ProductByIdAndNeed(wp_id, Integer.parseInt(currentCount));
		}
		response.getWriter().print(i);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
